package com.movitech.mobile.cz.base.bizconfig.controller;


import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.movitech.mobile.cz.base.modules.vo.PageRequestVO;
import com.movitech.mobile.cz.base.sys.bizvo.StrategicPartnersRequestVO;
import com.movitech.mobile.cz.base.bizconfig.entity.SStrategicPartners;
import com.movitech.mobile.cz.base.bizconfig.service.SStrategicPartnersService;
import com.movitech.mobile.cz.base.common.util.CommonConstants;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
 * <p>
 * SStrategicPartners 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-02-28
 */
@RestController
@RequestMapping("/v1/sStrategicPartners")
@Api(value = "战略合作伙伴基础操作接口", description = "战略合作伙伴基础操作接口")
public class SStrategicPartnersController {
    @Autowired
    @Qualifier("sStrategicPartnersService")
    private SStrategicPartnersService sStrategicPartnersService;

    @GetMapping("/allList")
    @ApiOperation(
            value = "获取所有战略合作伙伴接口",
            notes = "获取所有战略合作伙伴接口",
            response = SStrategicPartners.class
    )
    public RestReturnResult list() {
        RestReturnResult restReturnResult = RestReturnResult.success();
        Page<SStrategicPartners> page = sStrategicPartnersService.selectPage(new Page<SStrategicPartners>());
        restReturnResult.setData(page);
        return restReturnResult;
    }

//    @PostMapping("/searchList/{pageNumber}")
//    @ApiOperation(
//            value = "战略合作伙伴列表查询接口",
//            notes = "战略合作伙伴列表查询接口",
//            response = SStrategicPartners.class
//    )
//    public RestResult searchList(@RequestBody SStrategicPartners sStrategicPartners,
//                @ApiParam(value = "分页页数")@PathVariable Integer pageNumber) {
//        RestResult restResult = RestResult.success();
//        Page<SStrategicPartners> page = new Page<>();
//        page.setCurrent(pageNumber);
//        EntityWrapper wrapper = new EntityWrapper<>();
//        wrapper.setEntity(sStrategicPartners);
//        page = sStrategicPartnersService.selectPage(page,wrapper);
//        restResult.setObject(page);
//        return restResult;
//    }

    @PostMapping("/searchList/{pageNumber}")
    @ApiOperation(
            value = "战略合作伙伴列表查询接口",
            notes = "战略合作伙伴列表查询接口",
            response = SStrategicPartners.class
    )
    public RestReturnResult searchList(@RequestBody SStrategicPartners sStrategicPartners,
                @ApiParam(value = "分页页数")@PathVariable Integer pageNumber) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        Page<SStrategicPartners> page = new Page<>();
        page.setCurrent(pageNumber);
        EntityWrapper wrapper = new EntityWrapper<>();
        wrapper.setEntity(sStrategicPartners);
        page = sStrategicPartnersService.selectPage(page,wrapper);
        restReturnResult.setData(page);
        return restReturnResult;
    }

    @GetMapping("/getSStrategicPartners/{id}")
    @ApiOperation(
            value = "战略合作伙伴对象ID获取接口",
            notes = "战略合作伙伴对对象ID获取接口",
            response = SStrategicPartners.class
    )
    public RestReturnResult addSStrategicPartners(@PathVariable String id) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        SStrategicPartners sStrategicPartners = sStrategicPartnersService.selectById(id);
        restReturnResult.setData(sStrategicPartners);
        return restReturnResult;
    }

    @PostMapping("/add")
    @ApiOperation(
            value = "战略合作伙伴添加接口",
            notes = "战略合作伙伴添加接口",
            response = SStrategicPartners.class
    )
    public RestReturnResult add(@RequestBody SStrategicPartners sStrategicPartners) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        sStrategicPartnersService.insert(sStrategicPartners);
        restReturnResult.setData(sStrategicPartners);
        return restReturnResult;
    }

    @PutMapping("/update")
    @ApiOperation(
            value = "战略合作伙伴更新接口",
            notes = "战略合作伙伴更新接口",
            response = SStrategicPartners.class
    )
    public RestReturnResult update(@RequestBody SStrategicPartners sStrategicPartners) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        sStrategicPartnersService.updateById(sStrategicPartners);
        restReturnResult.setData(sStrategicPartners);
        return restReturnResult;
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(
            value = "战略合作伙伴通过ID删除接口",
            notes = "战略合作伙伴通过ID删除接口",
            response = SStrategicPartners.class
    )
    public RestReturnResult update(@PathVariable String id) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        sStrategicPartnersService.deleteById(id);
        return restReturnResult;
    }

    /**
     * 战略合作伙伴列表接口
     * @param pageRequestVO
     * @return
     */
    @ApiOperation(
            value = "战略合作伙伴列表接口",
            notes = "战略合作伙伴列表接口",
            response = SStrategicPartners.class
    )
    @RequestMapping(value = "/getStrategicPartnersList", method = RequestMethod.POST)
    @ResponseBody
    public RestReturnResult<Object> getStrategicPartnersList(@RequestBody PageRequestVO pageRequestVO){
        RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

        hResult = sStrategicPartnersService.getStrategicPartnersList(pageRequestVO);

        return hResult;
    }

    /**
     * 战略合作伙伴 新增/修改 接口
     * @param strategicPartnersRequestVO
     * @return
     */
    @ApiOperation(
            value = "战略合作伙伴 新增/修改 接口",
            notes = "战略合作伙伴 新增/修改 接口",
            response = SStrategicPartners.class
    )
    @RequestMapping(value = "/saveOrUpdateStrategicPartners", method = RequestMethod.POST)
    @ResponseBody
    public RestReturnResult<Object> saveOrUpdateStrategicPartners(@RequestBody StrategicPartnersRequestVO strategicPartnersRequestVO){
        RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

        try{
            hResult = sStrategicPartnersService.saveOrUpdateStrategicPartners(strategicPartnersRequestVO);
        }catch(Exception e){
            e.printStackTrace();
            hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
        }

        return hResult;
    }

    /**
     * 战略合作伙伴 删除 接口
     * @param id
     * @return
     */
    @ApiOperation(
            value = "战略合作伙伴 删除 接口",
            notes = "战略合作伙伴 删除 接口",
            response = SStrategicPartners.class
    )
    @RequestMapping(value = "/deleteStrategicPartners", method = RequestMethod.GET)
    @ResponseBody
    public RestReturnResult<Object> deleteStrategicPartners(String id){
        RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

        try{
            hResult = sStrategicPartnersService.updateStrategicPartnersForDel(id);
        }catch(Exception e){
            e.printStackTrace();
            hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
        }

        return hResult;
    }

    /**
     * 战略合作伙伴 启用/停用  接口
     * @param strategicPartnersRequestVO
     * @return
     */
    @ApiOperation(
            value = "战略合作伙伴 启用/停用  接口",
            notes = "战略合作伙伴 启用/停用  接口",
            response = SStrategicPartners.class
    )
    @RequestMapping(value = "/updateStrategicPartnersStatus", method = RequestMethod.POST)
    @ResponseBody
    public RestReturnResult<Object> updateStrategicPartnersStatus(@RequestBody StrategicPartnersRequestVO strategicPartnersRequestVO){
        RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

        try{
            hResult = sStrategicPartnersService.updateStrategicPartnersStatus(strategicPartnersRequestVO);
        }catch(Exception e){
            e.printStackTrace();
            hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
        }

        return hResult;
    }

}

